<template>
	<view>
		<image src="https://nc.heizixun.com/static/oldUser.jpg" v-if="userId" class="bg" mode="widthFix"></image>
		<image src="https://nc.heizixun.com/static/newUser1.jpg" v-else class="bg" mode="widthFix"></image>
		<view class="absolute-back"></view>

		<!-- 老朋友 -->
		<view v-if="userId">
			<view class="old old-big">
				{{newUser ? '领取成功' : '你好老朋友'}}
			</view>
			<view class="old old-sma" v-if="newUser">
				您的账户已收到活动回馈<br>
				奖励已自动发放完毕！
			</view>
			<view class="old old-sma" v-else>
				新人奖励仅针对未注册用户哦<br>
				邀请也能得好礼，快去参与吧
			</view>
			<view class="u-flex u-row-between btn-public">
				<view class="btn-bor btn-wid" @click="$navTo('pages/category/index')">
					去喝一杯
				</view>
				<view class="btn-back btn-wid" @click="oldInvite" v-if="userId && userInfo.invitee_id > 0">
					立即邀请
				</view>
				<button class="btn-back btn-wid" open-type="share" v-if="userId && userInfo.invitee_id == 0">
					立即邀请
				</button>
			</view>
		</view>

		<!-- 新朋友 -->
		<view class="btn btn-public u-flex-center" v-else @click="goLogin">
			注册领取奖励
		</view>
	</view>
</template>

<script>
	import * as UserApi from '@/api/user'
	export default {
		data() {
			return {
				userInfo: {},
				userId: null, //有id就是老用户
				newUser: null,
			}
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onShow() {
			this.userId = uni.getStorageSync('userId')
			if (this.userId) {
				// 获取当前用户信息
				this.getUserInfo()
			}
		},
		onLoad(options) {
			if (options.type == 'login' && options.isShare) {
				this.newUser = true
			} else {
				this.newUser = false
			}
		},
		methods: {
			// 获取当前用户信息
			getUserInfo() {
				const app = this
				UserApi.info()
					.then(result => {
						this.userInfo = result.data.userInfo
					})
			},
			// 跳去登录页
			goLogin() {
				if (uni.getStorageSync('managerId') == uni.getStorageSync('userId')) {
					uni.showToast({
						title: '您不能邀请自己哦~',
						icon: 'none'
					})
				} else {
					this.$navTo('pages/login/index?type=manager')
				}
			},
			oldInvite() {
				uni.showToast({
					title: '您已经邀请过了，没有机会了哦~',
					icon: 'none'
				})
			}
		},
		/**
		 * 设置分享内容
		 */
		onShareAppMessage() {
			return {
				title: '邀请有礼',
				path: '/pages/user/activity/manager?userId=' + uni.getStorageSync('userId')
			}
		},

		/**
		 * 分享到朋友圈
		 */
		onShareTimeline() {
			return {
				title: '邀请有礼',
				path: '/pages/user/activity/manager?userId=' + uni.getStorageSync('userId')
			}
		}
	}
</script>
<style>
	page {
		background: #fff;
	}
</style>
<style lang="scss" scoped>
	.bg {
		position: absolute;
		width: 100%;
		top: 0;
		left: 0;
		z-index: 2;
	}

	.absolute-back {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: #eafec1;
	}

	.btn-public {
		width: 80%;
		position: fixed;
		bottom: 40rpx;
		left: 0;
		right: 0;
		margin: 0 auto;
	}

	.btn {
		height: 80rpx;
		color: #fff;
		background: #70c215;
		border-radius: 50rpx;
	}

	.btn-wid {
		width: 48%;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50rpx;
	}

	.btn-bor {
		color: #70c215;
		border: 4rpx solid #70c215;
	}

	.btn-back {
		color: #fff;
		background: #70c215;
	}

	.old {
		position: absolute;
		left: 0;
		right: 0;
		margin: 0 auto;
		z-index: 3;
		text-align: center;
	}

	.old-big {
		top: 590rpx;
		color: #70c215;
		font-size: 50rpx;
		font-weight: bold;
	}

	.old-sma {
		color: #6d6d6d;
		top: 880rpx;
	}

	button {
		background: none;
		/* 移除背景色 */
		border: none;
		/* 移除边框 */
		padding: 0;
		/* 移除内边距 */
		margin: 0;
		/* 移除外边距 */
		font: inherit;
		/* 继承字体 */
		cursor: pointer;
		/* 鼠标悬停时显示手型 */
		color: inherit;
		/* 继承文字颜色 */
	}
</style>